/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hsos.samcomm.forumManagement.entity;

import de.hsos.samcomm.userManagement.entity.Member;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.validation.constraints.Size;

/**
 * Entität eines Eintrages.
 *
 * @author Felix
 */
@Entity(name="entry")
public class Entry implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String OID;
    @Size(min=1)
    private String title;
    @Size(min=1)
    private String text;
    private Member writtenBy;

    @ManyToOne(fetch= FetchType.EAGER)
    private Forum belongsTo;

    /**
     * Default Konstruktor.
     */
    public Entry() {}


    /**
     * überladener Konstruktor.
     *
     * @param title
     * @param text
     * @param writtenBy
     * @param belongsTo
     */
    public Entry(String title, String text, Member writtenBy, Forum belongsTo) {
        this.title = title;
        this.text = text;
        this.writtenBy = (Member)writtenBy;
        this.belongsTo = (Forum)belongsTo;
    }

    /**
     * Get-Methode für die ObjektID.
     *
     * @return oid
     */
    public String getOID() {
        return OID;
    }

    /**
     * Set-Methode für die ObjektID.
     *
     * @param OID
     */
    public void setOID(String OID) {
        this.OID = OID;
    }

    /**
     * Get-Methode für den Verfasser.
     *
     * @return the writtenBy
     */
    public Member getWrittenBy() {
        return writtenBy;
    }

    /**
     * Set-Methode für den Verfasser.
     *
     * @param writtenBy the writtenBy to set
     */
    public void setWrittenBy(Member writtenBy) {
        this.writtenBy = (Member)writtenBy;
    }

    /**
     * Get-Methode für das zugehoerige Forum.
     *
     * @return the belongsTo
     */
    public Forum getBelongsTo() {
        return belongsTo;
    }

    /**
     * Set-Methode für das zugehoerige Forum.
     *
     * @param belongsTo the belongsTo to set
     */
    public void setBelongsTo(Forum belongsTo) {
        this.belongsTo = (Forum)belongsTo;
    }

    /**
     * Get-Methode für den Titel.
     *
     * @return title
     */
    public String getTitle() {
        return title;
    }

    /**
     * Set-Methode für den Titel.
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Get-Methode für den Text.
     *
     * @return text
     */
    public String getText() {
        return text;
    }

    /**
     * Get-Methode für den Text.
     *
     * @param text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * überschriebene toString-Methode. Liefert den Text des Eintrages.
     *
     * @return text
     */
    @Override
    public String toString() {
        return text;
    }
}
